package com.javaking.clanteam.studentutils;

import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.javaking.clanteam.studentutils.courses.CoursesActivity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;



/**
 * @author scott
 *
 */
public class TaskSelectFragment extends ListFragment {
	
	List<Map<String,String>> mData;
	
	/**
	 * @see android.app.Fragment#onCreate(android.os.Bundle)
	 */
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		
		mData = new ArrayList<Map<String,String>>();
		
		Map<String,String> map = new HashMap<String,String>();
		map.put("taskName", "Manage Courses");
		map.put("intent", new Intent(getActivity(),CoursesActivity.class).toUri(0));
		
		mData.add(map);
		
		map = new HashMap<String, String>();
		map.put("taskName", "More to come....");
		mData.add(map);
		
		setListAdapter(new SimpleAdapter(getActivity(),mData,
				R.layout.fragment_taskselect_listitem,
				new String[] {"taskName"}, new int[] {R.id.taskName}));
	}
	
	/**
	 * @see android.app.ListFragment#onViewCreated(android.view.View, android.os.Bundle)
	 */
	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		
		getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
	}
	
	/**
	 * @see android.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_taskselect, container, false);
	}
	
	/**
	 * @see android.app.ListFragment#onListItemClick(android.widget.ListView, android.view.View, int, long)
	 */
	@Override
	public void onListItemClick(ListView l, View v, int position, long id) {
		try {
			startActivity(Intent.parseUri(mData.get(position).get("intent"),0));
		} catch (URISyntaxException e) {
			e.printStackTrace();
		} catch (NullPointerException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
